import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = (data, details) => {
    const requiredFields = [];
    if(!data || !data.brandId)
        requiredFields.push(
            formatMessage({
                id: 'validator.brandId',
                defaultMessage: '品牌'
            })
        );
    if(!data || !data.serviceEngineer)
        requiredFields.push(
            formatMessage({
                id: 'validator.serviceEngineer',
                defaultMessage: '售后服务工程师'
            })
        );
    if(!data || !data.qualityEngineer)
        requiredFields.push(
            formatMessage({
                id: 'validator.qualityEngineer',
                defaultMessage: '售后质量工程师'
            })
        );
    if(!data || !data.productCategoryId)
        requiredFields.push(
            formatMessage({
                id: 'validator.productCategoryId',
                defaultMessage: '车型'
            })
        );
    if(!data || !data.vehicleNature)
        requiredFields.push(
            formatMessage({
                id: 'validator.vehicleNature',
                defaultMessage: '车辆性质'
            })
        );
    if(!data || !data.frequency)
        requiredFields.push(
            formatMessage({
                id: 'validator.frequency',
                defaultMessage: '频次'
            })
        );
    if(!data || !data.faultPartCode)
        requiredFields.push(
            formatMessage({
                id: 'validator.faultPartCode',
                defaultMessage: '故障件代码'
            })
        );
    if(!data || !data.customerComplainQty)
        requiredFields.push(
            formatMessage({
                id: 'validator.customerComplainQty',
                defaultMessage: '客户抱怨数'
            })
        );
    if(!data || !data.outRescueQty)
        requiredFields.push(
            formatMessage({
                id: 'validator.outRescueQty',
                defaultMessage: '外出救援数'
            })
        );
    if(!data || !data.specialCompensateQty)
        requiredFields.push(
            formatMessage({
                id: 'validator.specialCompensateQty',
                defaultMessage: '客户特殊补偿数'
            })
        );
    if(!data || !data.carReturnQty)
        requiredFields.push(
            formatMessage({
                id: 'validator.carReturnQty',
                defaultMessage: '退换车数'
            })
        );
    if(!data || !data.marketValueFactor)
        requiredFields.push(
            formatMessage({
                id: 'validator.marketValueFactor',
                defaultMessage: '市场评价系数'
            })
        );
    if(!data || !data.warranty)
        requiredFields.push(
            formatMessage({
                id: 'validator.warranty',
                defaultMessage: '索赔数'
            })
        );
    if(!data || !data.importInfo)
        requiredFields.push(
            formatMessage({
                id: 'validator.importInfo',
                defaultMessage: '进口信息'
            })
        );
    if(!data || !data.causePartId)
        requiredFields.push(
            formatMessage({
                id: 'validator.causePartId',
                defaultMessage: '备件'
            })
        );
    if(!data || !data.failureRatio)
        requiredFields.push(
            formatMessage({
                id: 'validator.failureRatio',
                defaultMessage: '故障比例'
            })
        );
    if(!data || !data.occurCondition)
        requiredFields.push(
            formatMessage({
                id: 'validator.occurCondition',
                defaultMessage: '发生条件'
            })
        );
    if(!data || !data.problemDescribe)
        requiredFields.push(
            formatMessage({
                id: 'validator.problemDescribe',
                defaultMessage: '问题描述'
            })
        );
    if(!data || !data.servicePropose)
        requiredFields.push(
            formatMessage({
                id: 'validator.servicePropose',
                defaultMessage: '服务站处理情况及建议'
            })
        );
    if(!data || !data.problemSeverity)
        requiredFields.push(
            formatMessage({
                id: 'validator.problemSeverity',
                defaultMessage: '问题严重度'
            })
        );
    if(!data || !data.replyForm)
        requiredFields.push(
            formatMessage({
                id: 'validator.replyForm',
                defaultMessage: '回复形式'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    if(!details || (details && details.length === 0)) {
        message.warning(formatMessage({
            id: 'validator.message.detailQuantity',
            defaultMessage: '清单不能为空！'
        }));
        return false;
    }
    if(details.find(d => d.faultDescription === undefined || d.faultDescription === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.faultDescription',
            defaultMessage: '清单中故障描述必填!'
        })}`);
        return false;
    }
    if(details.find(d => d.inspectionProcess === undefined || d.inspectionProcess === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.inspectionProcess',
            defaultMessage: '清单中检查过程必填!'
        })}`);
        return false;
    }
    if(details.find(d => d.dealResult === undefined || d.dealResult === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.dealResult',
            defaultMessage: '清单中处理结果必填!'
        })}`);
        return false;
    }
    if(details.find(d => d.supplierCode === undefined || d.supplierCode === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.supplierCode',
            defaultMessage: '清单中供应商代码必填!'
        })}`);
        return false;
    }
    if(details.find(d => d.repairDate === undefined || d.repairDate === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.repairDate',
            defaultMessage: '清单中修理日期必填!'
        })}`);
        return false;
    }
    if(details.find(d => d.mileage === undefined || d.mileage === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.mileage',
            defaultMessage: '清单中行驶里程必填!'
        })}`);
        return false;
    }
    if(details.find(d => d.claimPrice === undefined || d.claimPrice === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.claimPrice',
            defaultMessage: '清单中索赔金额必填!'
        })}`);
        return false;
    }
    if(details.find(d => d.subDealerCode === undefined || d.subDealerCode === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.subDealerCode',
            defaultMessage: '清单中经销商编号必填!'
        })}`);
        return false;
    }
    if(details.find(d => d.subDealerName === undefined || d.subDealerName === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.subDealerName',
            defaultMessage: '清单中经销商名称必填!'
        })}`);
        return false;
    }
    return true;
};
export const newOrApproveOrderValidator = data => {
    const requiredFields = [];
    if(!data || !data.confirmComment) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.confirmComment',
            defaultMessage: '审核意见必填!'
        })}`);
        return false;
    }
    return true;
};

export const newOrImproveResultOrderValidator = data => {
    const requiredFields = [];
    if(!data || !data.improveSuggestion) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.improveSuggestion',
            defaultMessage: '改进建议或意见必填!'
        })}`);
        return false;
    }
    return true;
};
